<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="root"></div>
    <script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
    <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>
    <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
    <script type="text/babel">
         class RadioElement extends React.Component{
            constructor(props){
                super(props);
            }
            render(){
                return <div>
                    <label>{this.props.children}</label>    
                    <input type="radio" name={this.props.name} value="男"
                        checked={this.props.value == '男' ? true : false}
                        onChange={this.props.onChange}
                    /><label>男</label>
                    <input type="radio" name={this.props.name} value="女" 
                        checked={this.props.value == '女' ? true : false}
                        onChange={this.props.onChange}
                    /><label>女</label>
                </div>
            }
        }
         class InputElement extends React.Component{
            constructor(props){
                super(props);
            }
            render(){
                return <div>
                    <label>{this.props.children}</label>    
                    <input  
                        type={this.props.type} 
                        onBlur={this.props.validate} 
                        value={this.props.value}
                        onInput={this.props.onInput}
                    />
                    <span>{this.props.info}</span>
                </div>
            }
        }
        class MyComponent extends React.Component{
            constructor(props){
                super(props);
                this.state = {
                    value:"你好",
                    gender:"男"
                }
            }

            handleClick = (e) => {
                console.log(e.target)
                console.log(this.state.value,this.state.gender);
            }
            render(){
                return <div>
                        <input type="button" value="ok" onClick={this.handleClick}/>
                        <InputElement 
                            value={this.state.value}
                            onInput={(e) => this.setState({value:e.target.value})}
                        
                        >用户名：</InputElement>
                        <RadioElement value={this.state.gender} name="gender"
                            onChange={(e) => this.setState({gender:e.target.value})}
                        >性别：</RadioElement>
                    </div>
            }
        }

        ReactDOM.createRoot(document.getElementById("root")).render(<MyComponent />);
    </script>
</body>
</html>